
import 'package:shared_preferences/shared_preferences.dart';

/**
 * 轻量级缓存工具
 */

class FFSpUtils {
  static SharedPreferences? _sharedPreferences;

  ///初始化，在程序最开始的地方调用
  static Future init() async {
    _sharedPreferences ??= await SharedPreferences.getInstance();
  }

  static String? getData(String key) {
    if (_sharedPreferences == null) {
      return "";
    }
    return _sharedPreferences!.getString(key);
  }

  static Future saveData(String key, String data) async {
    return await _sharedPreferences!.setString(key, data);
  }

  static bool getBoolData(
    String key,
  ) {
    return _sharedPreferences!.getBool(key) ?? false;
  }

  static Future remove(String key) async {
    return await _sharedPreferences!.remove(key);
  }

  static Future saveBoolData(String key, bool data) async {
    return await _sharedPreferences!.setBool(key, data);
  }

  static int? getIntData(
    String key,
  ) {
    return _sharedPreferences!.getInt(key);
  }

  static Future saveIntData(String key, int data) async {
    return await _sharedPreferences!.setInt(key, data);
  }
}
